package com.sze.volanmenetrendgyor;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

public class StationsActivity extends Activity {

    private ListView mLista;
    private StationSpecialAdapter mSpecialAdapter;
    private ArrayList<StationClass> mListArray = new ArrayList<StationClass>();

    // http://ihm.trumind.hu/api?task=getLineStops&line=2&dir=1
    @Override
    protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	setContentView(R.layout.linesdetaillayout);

	mLista = (ListView) findViewById(R.id.stationList);
	mSpecialAdapter = new StationSpecialAdapter(this, mListArray, R.layout.stationslistitem, new int[] { R.id.stationslistitemtextview });
	mLista.setAdapter(mSpecialAdapter);

	// TODO net checker
	new StationsDownloader().execute(this);

    }

    private class StationsDownloader extends StationDownloadTask {
	@Override
	protected void onPostExecute(Boolean result) {

	    if (ex != null) {
		Log.d("ERROR:", ex.getMessage());
	    }
	    Log.d("VOLAN", "Lines list download finished");
	    new StationGetter().execute(StationsActivity.this);
	    super.onPostExecute(result);
	}
    }

    private class StationGetter extends StationListTask {

	@Override
	protected void onPostExecute(ArrayList<StationClass> result) {
	    if (result != null && result.size() > 0) {
		for (StationClass stationClass : result) {
		    mListArray.add(stationClass);
		}
		mSpecialAdapter.notifyDataSetChanged();
	    }
	    super.onPostExecute(result);
	}
    }

}
